package com.pany.rememberpass;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

import java.io.ByteArrayOutputStream;

/**
 * @name： RememberPass
 * @author： zs
 * @time： 2022/5/7 0007
 */
public class ImageUtil {
    public static String imageToBase64(Bitmap bitmap) {

        ByteArrayOutputStream byteArrayoutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayoutputStream);
        byte[] buffer = byteArrayoutputStream.toByteArray();
        String baseStr = Base64.encodeToString(buffer, Base64.DEFAULT);
        return baseStr;


    }

    public static Bitmap base64ToImage(String bitmap64) {

        byte[] bytes = Base64.decode(bitmap64, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
        return bitmap;
    }
}
